﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UIShare;

using EFong.View.Proxy;

namespace EFong.View.Login
{
    public partial class Frm_ChangePassword : BasicForm
    {
        private BaseServiceProxy _baseServiceProxy;

        public Frm_ChangePassword()
        {
            InitializeComponent();
        }

        protected override void InitFields()
        {
            _baseServiceProxy = BaseServiceProxy.GetInstance();
        }

        protected override void Events()
        {
            this.btn_OK.Click += (s, e) => { this.changePassword(); };
        }

        protected override void LoadDatas()
        {
            lbl_Caption.Text = AppParameters.SystemName;
        }

        private void changePassword()
        {
            if(this.txt_NewPwd.Text.Trim() != this.txt_ConfirmPwd.Text.Trim())
            {
                MsgBox.Error("两次密码输入不相同.");
                return;
            }

            if (_baseServiceProxy.ModifyUserPassword(this.txt_User.GetText().Trim(), this.txt_Pwd.GetText().Trim(), this.txt_NewPwd.GetText().Trim()).IsSuccess)
            {
                MsgBox.Info("修改成功.");
                this.Close();
            }
        }

        public string UserName
        {
            get { return txt_User.GetText(); }
            set { txt_User.SetText(value); }
        }

        public string Password
        {
            get { return txt_Pwd.GetText(); }
            set { txt_Pwd.SetText(value); }
        }
    }
}
